AI Voice Chat using Webhook, Memory Manager, OpenAI, Google Gemini & ElevenLabs

工作流概述

这是一个包含15个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "TtoDcjgthgA4NTkU",
  "meta": {
    "instanceId": "fb261afc5089eae952e09babdadd9983000b3d863639802f6ded8c5be2e40067",
    "templateCredsSetupCompleted": true
  },
  "name": "AI Voice Chat using Webhook, Memory Manager, OpenAI, Google Gemini & ElevenLabs",
  "tags": [
    {
      "id": "mqOrNvCDgQLzPA2x",
      "name": "Workflows",
      "createdAt": "2024-08-07T14:18:53.614Z",
      "updatedAt": "2024-08-07T14:18:53.614Z"
    }
  ],
  "nodes": [
    {
      "id": "86cbf150-df4f-42f7-b7b3-e03c32e6f23c",
      "name": "Get Chat",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        1700,
        -400
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "a9153a24-e902-4f29-9b83-447317ce3119",
      "name": "Insert Chat",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        2540,
        -400
      ],
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "user",
              "message": "={{ $('OpenAI - Speech to Text').item.json[\"text\"] }}"
            },
            {
              "type": "ai",
              "message": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "f5c272d4-248b-45a5-87b5-eb659a865d05",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1664,
        -491
      ],
      "parameters": {
        "color": 6,
        "width": 486.4746124819703,
        "height": 238.4911357933579,
        "content": "## Get Context"
      },
      "typeVersion": 1
    },
    {
      "id": "32ad17ca-0045-487d-9387-71c2e73629d4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2510,
        -489
      ],
      "parameters": {
        "color": 6,
        "width": 321.2536584847704,
        "height": 231.05945912581728,
        "content": "## Save Context"
      },
      "typeVersion": 1
    },
    {
      "id": "17ae4f1a-6192-4c52-8157-3cb47b37e0fb",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2020,
        -400
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "context"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "00b3081e-fbcd-489b-b45a-4e847c346594",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        2080,
        -100
      ],
      "parameters": {
        "sessionKey": "test-0dacb3b5-4bcd-47dd-8456-dcfd8c258204",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.2
    },
    {
      "id": "55ca2790-e905-414a-a9f6-7d88a9e5807d",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2220,
        -100
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-1.5-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "2bUF1ZI9hoMIM5XN",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e8b3433f-b205-404c-9f05-504556d6b6dd",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        3560,
        -400
      ],
      "parameters": {
        "options": {},
        "respondWith": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "id": "de296743-5ac7-454b-bf3a-d020cc024511",
      "name": "ElevenLabs - Generate Audio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3240,
        -400
      ],
      "parameters": {
        "url": "=https://api.elevenlabs.io/v1/text-to-speech/{{voice id}}",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $('Basic LLM Chain').item.json.text }}"
            }
          ]
        },
        "genericAuthType": "httpCustomAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "lnGfV4BlxSE6Xc4X",
          "name": "Eleven Labs"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "214e15f2-8a16-4598-b4ac-9fc2ec6545e6",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3040,
        -560
      ],
      "parameters": {
        "width": 468.73250812192407,
        "height": 843.7602354099661,
        "content": "* ### For the Text-to-Speech part, we'll use ElevenLabs.io, which is free and offers a variety of voices to choose from. However, you can also use the OpenAI `\"Generate audio\"` node instead.

















* ### Since there is no pre-built node for `\"ElevenLabs\"` in n8n, we'll connect to it through its API using the \"HTTP Request\" node.

## Prerequisites:
* ### `\"ElevenLabs API Key\"` (you can obtain it from their website).
* ### `\"Voice ID\"` (you can also get it from ElevenLabs' \"Voice Library\").
## Setup
* ### In the URL parameter, replace \"{{voice id}}\" at the end of the URL with the Voice ID you obtained from ElevenLabs.io.
* ### To set up your API Key, add custom authentication and include the following `JSON` with your acual ElevenLabs API Key:
```json
{
  \"headers\": {
    \"xi-api-key\": \"put-your-API-Key-here\"
  }
}
```"
      },
      "typeVersion": 1
    },
    {
      "id": "94ad934c-4a13-47b1-83a5-76fab43b3a47",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1663,
        -598
      ],
      "parameters": {
        "color": 6,
        "width": 487.4293487597613,
        "height": 91.01435855269375,
        "content": "### The \"Get Chat,\" \"Insert Chat,\" and \"Window Buffer Memory\" nodes will help the LLM model maintain context throughout the conversation."
      },
      "typeVersion": 1
    },
    {
      "id": "0a96f48d-0d8b-4240-9eab-a681bfd4c8b5",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        2900,
        -400
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9a5d4ddb-6403-4758-858e-9fbe10c421a9",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        2200,
        -400
      ],
      "parameters": {
        "text": "={{ $('OpenAI - Speech to Text').item.json[\"text\"] }}",
        "messages": {
          "messageValues": [
            {
              "type": "AIMessagePromptTemplate",
              "message": "=To maintain context and fully understand the user's question, always review the previous conversation between you and him before providing an answer.
This is the previous conversation:
{{ $('Aggregate').item.json[\"context\"].map(m => `
Human: ${m.human || 'undefined'}
AI Assistant: ${m.ai || 'undefined'}
`).join('') }}"
            }
          ]
        },
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "f2f99895-9678-41b8-ad28-db40e1e23dc0",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1320,
        -400
      ],
      "webhookId": "e9f611eb-a8dd-4520-8d24-9f36deaca528",
      "parameters": {
        "path": "voice_message",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "d9a5fb04-4c02-4da4-b690-7b0ecd0ae052",
      "name": "OpenAI - Speech to Text",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1500,
        -400
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe",
        "binaryPropertyName": "voice_message"
      },
      "credentials": {
        "openAiApi": {
          "id": "2Cije3KX7OIVwn9B",
          "name": "n8n OpenAI"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "versionId": "fe5792ca-03d7-4cdd-96db-20f4cd479c7e",
  "connections": {
    "Limit": {
      "main": [
        [
          {
            "node": "ElevenLabs - Generate Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "OpenAI - Speech to Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Chat": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Chat": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Insert Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "Insert Chat",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "Get Chat",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Speech to Text": {
      "main": [
        [
          {
            "node": "Get Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "ElevenLabs - Generate Audio": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • @N8N/N8N Nodes Langchain.Memorymanager
  • Stickynote
  • Aggregate
  • @N8N/N8N Nodes Langchain.Memorybufferwindow
  • @N8N/N8N Nodes Langchain.Lmchatgooglegemini

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作